using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace Pick_List_Test
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                DataTable table = new DataTable();
                table.Columns.Add(new DataColumn("BookId", typeof(Int16)));
                table.Columns.Add(new DataColumn("BookName", typeof(String)));

                table.Rows.Add(1, "The Partner");
                table.Rows.Add(2, "The Firm");
                table.Rows.Add(3, "The Pelican Brief");
                table.Rows.Add(4, "The Chamber");
                table.Rows.Add(5, "The Broker");
                table.Rows.Add(6, "A Painter House");

                this.PickList1.DataSource = table;
                this.PickList1.DataTextField = "BookName";
                this.PickList1.DataValueField = "BookId";

                this.PickList1.DataBind();
                this.PickList1.SetSelectedValues(3, 4);
            }
        }

        private void WriteSelectedItems()
        {
            string html;

            html = "<b>Selected Items</b><br><ul>";

            foreach (ListItem item in this.PickList1.GetSelectedItems())
            {
                html += "<li>" + item.Text + ", Value = " + item.Value + "</li>";
            }

            html += "</ul><br/><br/>";

            this.Literal1.Text += html;
        }
        private void WriteAddedItems()
        {
            string html;

            html = "<b>Added Items</b><br><ul>";

            foreach (ListItem item in this.PickList1.GetAddedItems())
            {
                html += "<li>" + item.Text + ", Value = " + item.Value + "</li>";
            }
            
            html += "</ul><br/><br/>";

            this.Literal1.Text += html;
        }
        private void WriteRemovedItems()
        {
            string html;

            html = "<b>Removed Items</b><br><ul>";

            foreach (ListItem item in this.PickList1.GetRemovedItems())
            {
                html += "<li>" + item.Text + ", Value = " + item.Value + "</li>";
            }
           
            html += "</ul><br/><br/>";

            this.Literal1.Text += html;
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            this.WriteSelectedItems();
            this.WriteAddedItems();
            this.WriteRemovedItems();
            this.PickList1.BaselineValues();
        }
    }
}
